/**
  layer.h - Created by Timothy Morey on 6/11/2012
*/

#ifndef __LAYER_H
#define __LAYER_H

#include <libxml/tree.h>

#include "color-ramp.h"
#include "data-schema.h"
#include "data-source.h"
#include "grid-mask.h"
#include "libnvn.h"
#include "renderer.h"

#define INVALID_LAYER -1

typedef struct
{
  RendererType RendererType;

  ColorRamp ColorRamp;

  DataSourceDescriptor DataSource;
  DataGridSchema DataSchema;
  int XDimension;
  int YDimension;
  int TDimension;

  int MaintainAspectRatio;

  int UseMask;
  GridMaskDef MaskDef;
  DataSourceDescriptor MaskSource;
  DataGridSchema MaskSchema;
} LayerProperties;

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int CreateLayer(LayerProperties props, int* layer);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int DestroyLayer(int layer);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int DrawLayer(int layer, int frame);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int GetDataHeight(int layer, int* height);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int GetDataWidth(int layer, int* width);

/**
  Gets the current frame index for the specified layer.  If the layer does not
  have any frames, or if the current frame index is invalid, NVN_EINVFRAME will
  be returned.

  @param layer The layer of interest.
  @param frame The storage location for the frame index.

  @return An nvn error code indicating if the operation was successful.
*/
EXPORT int GetLayerCurrentFrame(int layer, int* frame);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int GetLayerFrameCount(int layer, int* count);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int GetNextFrameIndex(int layer, int frame, int* next);

/**
  Indicates if the layer has complete data for the specified frame.

  @param[in] layer The layer of interest.
  @param[in] frame The frame index of interest.
  @param[out] complete This value will be set to 1 if the layer has the complete
  data for the specified frame, and 0 otherwise.

  @return An nvn error code indicating the success of the operation.
*/
EXPORT int HasCompleteFrame(int layer, int frame, int* complete);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int ParseLayerProperties(xmlNodePtr root, LayerProperties* props);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int SaveLayerProperties(LayerProperties props, xmlNodePtr* root);

/**
  Sets the current frame index for the layer, which identifies the frame that
  will be drawn by the window.

  @param layer The layer of interest.
  @param frame The index of the current frame.

  @return An nvn error code indicating if the operation was successful.
*/
EXPORT int SetLayerCurrentFrame(int layer, int frame);

/**
  @return An nvn error code indicating the success of the operation.
*/
EXPORT int UpdateLayerTransform(int layer, int width, int height);

#endif
